//
//  ViewController.swift
//  C013_test_ui_events
//
//  Created by yao_yu on 15/7/11.
//  Copyright © 2015年 yao_yu. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
    
    var result = UILabel(frame: CGRectMake(20, 60, 200, 30))

    override func viewDidLoad() {
        super.viewDidLoad()

        let aButton = UIButton(type: UIButtonType.System)
        aButton.frame = CGRectMake(20, 30, 200, 30)
        aButton.setTitle("测试", forState: UIControlState.Normal)
        aButton.addTarget(self, action: "onTest", forControlEvents: UIControlEvents.TouchUpInside)
        view.addSubview(aButton)
        view.addSubview(result)
    }

    func onTest() {
        a++
        b++
        d += a
        c += 2
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


    var a:Int = 0 {
        didSet {
            view.setNeedsLayout()
        }
    }
    
    var b:Int = 0 {
        didSet {
            view.setNeedsLayout()
        }
    }
    
    var c:Int = 0 {
        didSet {
            view.setNeedsLayout()
        }
    }
    
    var d:Int = 0 {
        didSet {
            view.setNeedsLayout()
        }
    }
    
    override func viewDidLayoutSubviews() {
        print((a,b,c,d))
        result.text = "(\(a), \(b), \(c), \(d))"
    }
}

